package com.blue.base.oauth.server.controller;

import com.blue.base.oauth.common.dto.OAuthClientDetailDto;
import com.blue.base.oauth.server.entity.OauthClientDetails;
import com.blue.base.oauth.server.service.OAuthClientDetailsService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author liulei
 * @version 1.0
 */
@Slf4j
@RestController
@RequestMapping("/client")
public class ClientDetailsController {

    @Autowired
    private OAuthClientDetailsService oAuthClientDetailsService;

    @GetMapping("/ui")
    @ApiOperation(value = "添加客户端detailUi", notes = "添加客户端detailUi")
    public String addClientUi() {
        return "client";
    }

    @PostMapping("/add")
    @ApiOperation(value = "添加客户端detail", notes = "添加客户端detail")
    public String addClient(OAuthClientDetailDto client) {
        log.info("添加客户端detail:{}", client);
        OauthClientDetails oauthClientDetails = new OauthClientDetails();
        BeanUtils.copyProperties(client, oauthClientDetails);
        oAuthClientDetailsService.save(oauthClientDetails);
        return "ok";
    }

}
